<template>
  <a-modal title='银行流水选择(可通过双击行选择)' width='85%' :visible='visible' :confirmLoading='loading' :footer='null' @ok='handleSubmit' @cancel='close'>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='交易日期' type='range' name='beginDate' />
      <f-search-form-item label='单位名称' name='customName' placeholder='单位名称或者首字母' />
      <f-search-form-item label='交易银行' ref='bank' type='select' name='takeBankId' :data='api.bank.list' valueKey='bankId' label-key='bankName' :required='true' />
    </f-search-form>
    <f-table ref='table' v-if='visible' rowKey='bankStatementId' @dblclick='dblclick' :columns='columns' :multiple='false' :operator='operator' :params='queryParam' :api='api.bbs' handler='bankStatementSelectPageListHandler'>
     <span slot='action' slot-scope='text, record'>
          <template v-if='record.amountState==0'>
             <a-dropdown>
             <a class='ant-dropdown-link'>更多<a-icon type='down' /></a>
             <a-menu slot='overlay'>
               <a-menu-item >
                   <a href='javascript:;' @click='updateBankStatementState(record)'>标记为已认款</a>
               </a-menu-item>
             </a-menu>
            </a-dropdown>
          </template>
     </span>
    </f-table>
  </a-modal>
</template>
<script>
import api from "../js/api"

export default {
  name: "SelectBankStatementModal",
  props: {},
  data() {
    let operator = []
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      loading: false,
      visible: false,
      selectedRowKeys: [],
      selectedRows: [],
      //列表初始化查询参数
      queryParam: {
        amountState: 0
      },

      // 表头
      columns: [
        {
          title: "序号",
          width: "50px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "客户名称",
          align: "left",
          ellipsis: true,
          width: "140px",
          dataIndex: "customName"
        },
        {
          title: "账套",
          align: "left",
          ellipsis: true,
          width: "100px",
          dataIndex: "companyName"
        },
        {
          title: "收款账户",
          width: "80px",
          align: "left",
          ellipsis: true,
          dataIndex: "bankName"
        },
        {
          title: "支付账户",
          width: "140px",
          align: "left",
          ellipsis: true,
          dataIndex: "bankNo"
        },
        {
          title: "交易金额",
          align: "left",
          width: "80px",
          dataIndex: "amount"
        },
        {
          title: "交易日期",
          align: "left",
          width: "130px",
          ellipsis: true,
          dataIndex: "amountDate"
        },
        {
          title: "备注",
          align: "left",
          width: "100px",
          ellipsis: true,
          dataIndex: "remark"
        },
        {
          title: "摘要",
          width: "100px",
          align: "left",
          ellipsis: true,
          dataIndex: "abstract"
        },{
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "90px",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  methods: {
    open(params) {
      this.queryParam = params
      this.visible = true
      this.selectedRowKeys = []
      this.selectedRows = []
      this.$refs.table.refresh(true, params)
    },
    close() {
      this.$emit("close")
      this.visible = false
    },
    dblclick(record, event) {
      let selectedRowKeys = []
      let selectedRows = []
      selectedRowKeys.push(record.bankStatementId)
      selectedRows.push(record)
      this.$emit("onSelectChange", selectedRowKeys, selectedRows)
      this.close()
    },
    handleSubmit() {
      this.$emit("onSelectChange", this.selectedRowKeys, this.selectedRows)
      this.close()
    },
    //更新认款状态
    updateBankStatementState(record) {
      this.http.confirm(this, {
        content: "确认标记为已认款吗?",
        url: api.bbs.setAmountState,
        data: {
          ids: record.bankStatementId,
          amountState: 1
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  },
  created() {
  },
  components: {}
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
